<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
        <meta content="telephone=no" name="format-detection" />
        <title>推广审核</title>
        <link href="{{asset('/mobile/css/style.css')}}" rel="stylesheet" type="text/css">
    </head>
    <style type="text/css">
        body{
            background-color: #F1F1F1;
        }
        input{
            border: none;
            outline: none;
        }
        .tab-wrap{
            display: flex;
        }
        .tab{
            background-color: #FFFFFF;
            color: #D9543B;
            flex: auto;
            text-align: center;
            padding: 15px 0;
        }
        .tab.active{
            background-color: #D9543B;
            color: #FFFFFF;
        }
        .inp-wrap{
            background-color: #FFFFFF;
            margin: 25px 0;
        }
        .inp{
            width: 80%;
            padding: 15px 0;
            margin-left: 15px;
            font-size: 1.1rem;
        }
        .btn-big{
            text-align: center;
            background-color: #D9543B;
            border-radius: 5px;
            font-size: 1.1rem;
            padding: 0.7rem 0;
            color: #F9EAE7;
            width: 90%;
            margin: 0 auto;
        }
        #con2{
            display: none;
        }
        
    </style>
    <body>
        <div class="tab-wrap">
            <div class="tab active" data-type="0">通过</div>
            <div class="tab" data-type="1">驳回</div>
        </div>

        <div id="con1">
            <form action="/mobile/agent/do_audit/{{$agent->id}}" method="POST">
                {{csrf_field()}}
                <input type="hidden" name="status" value="1">
                <div class="inp-wrap">
                    <input class="inp" type="number" name="divide" id="ypNum" placeholder="请设置推广员分成比例（1-100整数）" value="{{old('divide')}}"/><br>
                    <span style="font-size:16px;color:#ccc;text-indent:2em;text-align:center">&nbsp;&nbsp;&nbsp;&nbsp;当前设置比例为<span style="font-size:18px;color:red" class="input-divide"></span><br>&nbsp;&nbsp;&nbsp;&nbsp;下级购买一张银票(房卡)他的分成是<span class="divide-money" style="font-size:18px;color:red"></span> </span>
                </div>
                <div class="btn-big" id="go">提交申请</div>
            </form>
        </div>
            @if ($errors->any())          
              {{ $errors->first() }}
            @endif
        <div id="con2">
            <form action="/mobile/agent/do_audit/{{$agent->id}}" method="POST">
                {{csrf_field()}}
                <input type="hidden" name="status" value="2">
                <div class="inp-wrap">
                    <input class="inp" name="reject_reason" type="text" id="bhInp" placeholder="请输入驳回原因" />
                </div>
                <div class="btn-big" id="go2">提交申请</div>
            </form>    
        </div>
        
    <script type="text/javascript" src="{{asset('/mobile/js/jquery-1.8.3.min.js')}}"></script>
    <script type="text/javascript">
        $('.tab').on('touchstart', function() {
            $(this).addClass('active')
            $(this).siblings().removeClass('active')    
            var type = $(this).attr('data-type')
            if (type == 0) {
                console.log('点击的通过')
                $('#con1').show()
                $('#con2').hide()
            } else {
                console.log('点击的驳回')
                $('#con2').show()
                $('#con1').hide()
            }
        })
        $('#go').on('touchstart', function() {
            var ypNum = $('#ypNum').val()
            if (!ypNum) {
                alert('请输入分成比例')
            } else {
                console.log('提交申请' + ypNum)
            }
        })
        $('#go2').on('touchstart', function() {
            var bhStr = $('#bhInp').val()
            if (!bhStr) {
                alert('请输入驳回原因')
            } else {
                console.log('驳回原因' + bhStr)
            }
        });
        
        $(".btn-big").click(function(){
            $(this).parents("form").submit();
        });
        $('#ypNum').on('input propertychange',function(){
            var val = $(this).val();
            if (isRealNum(val)) {
                var my_divide = "{{$my->divide}}";
                var money = 0.5 * (my_divide / 100) * (val / 100);
            　　$('.input-divide').html(val+'%');
            　　$('.divide-money').html(money+'元');
            }
        });

        function isRealNum(val){
            // isNaN()函数 把空串 空格 以及NUll 按照0来处理 所以先去除
            if(val === "" || val ==null){
                return false;
            }
            if(!isNaN(val)){
                return true;
            }else{
                return false;
            }
        }
    </script>
    </body>
</html>
